package cn.cpf.app.pane;


import com.github.cpfniliu.common.util.io.IoUtils;

import java.awt.*;
import java.awt.datatransfer.*;
import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * <b>Description : </b>
 *
 * @author CPF
 * Date: 2020/4/22 9:32
 */
public class PicBedHub {

    public static void test() throws IOException, UnsupportedFlavorException {
        Image imageFromClipboard = getImageFromClipboard();
        String path = "D:\\biz\\tmp\\";
        String fileName = "pic-bed" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd-hhmmssSSS")) + ".png";
        final String filePath = path + fileName;
        IoUtils.savePic(imageFromClipboard, new File(filePath), "png");

        // 保存至系统剪贴板
        StringSelection stsel = new StringSelection(String.format("![%s](%s)", fileName, filePath));
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stsel, stsel);
    }

    public static Image getImageFromClipboard() throws IOException, UnsupportedFlavorException {
        Clipboard sysc = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable cc = sysc.getContents(null);
        if (cc != null && cc.isDataFlavorSupported(DataFlavor.imageFlavor)) {
            return (Image) cc.getTransferData(DataFlavor.imageFlavor);
        }
        return null;
    }

    // 1. 将一个项目中的文件夹的图片标准化
    // 2. 批量下载网络图片到本地标准化
    // 3. 修改图床
    public static void formatPic() {
        String dirPath = "P:\\git\\document";


    }

}
